package view.drawing;

import loadsave.Parser;
import loadsave.loadsaveobject.Iterator;
import loadsave.loadsaveobject.LoadSaveObject;

public class LoadTester {
	
	public static void main(String[] args) {
	
			loadDrawManager("data/entity.oml");
			loadDrawManager("data/items.oml");
			loadDrawManager("data/terrain.oml");
			loadDrawManager("data/decals.oml");
	}
	
	private static void loadDrawManager(String filename) {
		DrawManager dm = DrawManager.getInstance();
		
		try {
			
		
			// Parse entity
			LoadSaveObject lso = Parser.parse(filename);
			
			LoadSaveObject lsoDM = lso.get("manager");
			
			LoadSaveObject lsoModelSheets = lsoDM.get("mModelSheets");
			
			Iterator<LoadSaveObject> it = lsoModelSheets.getIterator();
			
			for (it.init(); it.hasNext(); it.next()) {
				
				
				String name = it.getCurrKey().getValue();
				SpriteSheetSet set = new SpriteSheetSet();
				
				// Load the set
				
				LoadSaveObject setObject = it.getCurrVal();
				LoadSaveObject sheetsObject = setObject.get("mSheets");
				Iterator<LoadSaveObject> itSet = sheetsObject.getIterator();
				
				for (itSet.init(); itSet.hasNext(); itSet.next()) {
					String setStateName = itSet.getCurrKey().getValue();
					
					// Load the sprite sheet
					LoadSaveObject sheetObj = itSet.getCurrVal();
					String filePath = sheetObj.get("mImagePath").getValue();
					
					SpriteSheet sheet = new SingleFrameSpriteSheet(filePath);
					set.addSpriteSheet(setStateName, sheet);
					
					System.out.format("Loaded SpriteSheet: {name=%s state=%s path=%s}\n", name, setStateName, filePath);
				}
				
				
				dm.addSpriteSheetSet(name, set);
				
				
			}
		}
		catch (Exception ex) {
			
		}
	}
	

}
